$(document).ready(function(){
	$('#submit').click(function(){
		$('form').submit();
	});
	
	$('#info_serie').click(function() {
		id_tvdb =  $('input[name="id_tvdb"]:checked').val();
		noSeason =  $('#noSeason').val();
		noEpisode =  $('#noEpisode').val();
		
		if(id_tvdb != undefined && noSeason != '' && noEpisode != ''){
			ajax_get_info_episode(id_tvdb, noSeason, noEpisode);
		}
		else if(noSeason == ''){
			alert('Introduzca un numero de Temporada');
		}
		else if(noEpisode == ''){
			alert('Introduzca un numero de Episodio');
		}
		else{
			alert('Seleccione una Serie de la Lista');
		}
		
	});
});

function ajax_get_info_episode(id_tvdb, noSeason, noEpisode){
	$.ajax({
		type: "POST",
		url: base_url+lang_url+'panel/series/get_info_episode',
		data: 'tvdb_id='+id_tvdb+'&season='+noSeason+'&episode='+noEpisode,
		dataType: 'json',
		success: function(rsp){
			if(rsp.hasOwnProperty('error')==false){
				
				window.parent.$('#title').val(rsp.original_name);
				window.parent.$('#no_episode').val(rsp.episode);
				window.parent.$('#sinopsis_spa').val(rsp.synopsis_spa);
				window.parent.$('#sinopsis_eng').val(rsp.synopsis_eng);
				
//				window.parent.$('#languaje').val('Ingles');
//				window.parent.$('#subtitles').val('Español');
//				window.parent.$('#format_episode').val('MP4');
//				window.parent.$('#quality').val('HDTV');
				window.parent.$('#date_release').val(rsp.released);
				
				
				window.parent.$("p.close a").click();
			}
			else{
				alert(rsp.error);
			}
			
		},
		error: function(e){
			alert('Error:' + e);
		}
	});
}